/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package IDSNN_1_Data;
import java.io.*;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
 *
 * @author francisco
 */
public class TrainSet {
    
    private String dir;
    private double[][] inputTest;
    private double[][] resultTest;
    private BufferedWriter out;
    private FileWriter fstream;
    private File file;
    private FileInputStream fis;
    private BufferedInputStream bis;
    private DataInputStream dis;
    
    public TrainSet(String dir, boolean write)
    {
        this.dir=dir;
        try{
            if(write)
            {
                fstream = new FileWriter(dir);
                out = new BufferedWriter(fstream);
            }
            else
            {
                file = new File(dir);
                fis = new FileInputStream(file);
                bis = new BufferedInputStream(fis);
                dis = new DataInputStream(bis);  
            }
        }catch(Exception ex){
            ex.printStackTrace();
        }
    }
    
    public void createTrainSet(String data) {
        try
        {  
            out.append(data);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        finally
        {
        }
    }
    
    public void closeSet(){
        try {
            out.close();
        } catch (IOException ex) {
            Logger.getLogger(TrainSet.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    
    public void readTS(){
     int nl=0;
     String[] aux = new String[9];
     try
     {
        LineNumberReader lnr = new LineNumberReader(new FileReader(file));
        lnr.skip(Long.MAX_VALUE);
        nl = lnr.getLineNumber();
        inputTest = new double[nl][11];
        resultTest = new double[nl][1];
        double[] auxArray;
        double[] auxArray2;
        int count=0;
        while(dis.available()!=0){
            auxArray = new double[13];
            auxArray2 = new double[1];
            aux = dis.readLine().split(";");
            auxArray[0] = Double.valueOf(aux[0]).doubleValue();
            auxArray[1] = Double.valueOf(aux[1]).doubleValue();
            auxArray[2] = Double.valueOf(aux[2]).doubleValue();
            auxArray[3] = Double.valueOf(aux[3]).doubleValue();
            auxArray[4] = Double.valueOf(aux[4]).doubleValue();
            auxArray[5] = Double.valueOf(aux[5]).doubleValue();
            auxArray[6] = Double.valueOf(aux[6]).doubleValue();
            auxArray[7] = Double.valueOf(aux[7]).doubleValue();
            auxArray[8] = Double.valueOf(aux[8]).doubleValue();
            auxArray[9] = Double.valueOf(aux[9]).doubleValue();
            auxArray[10] = Double.valueOf(aux[10]).doubleValue();
            auxArray[11] = Double.valueOf(aux[11]).doubleValue();
            auxArray[12] = Double.valueOf(aux[12]).doubleValue();
            inputTest[count] = auxArray.clone();
            auxArray2[0] = Double.valueOf(aux[13]).doubleValue();
            resultTest[count] = auxArray2.clone();
            count++;
        }
        fis.close();
        bis.close();
        dis.close();
     }
     catch(Exception ex)
     {
         ex.printStackTrace();
     }
    }
    
    public double[][] getInputTest(){
        return inputTest;
    }
    
    public double[][] getResultTest(){
        return resultTest;
    }
    
}
